package com.lawalong.redbubblemicroservice.util;

import com.lawalong.redbubblemicroservice.model.Treasure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.util.ResourceUtils;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.awt.*;
import java.io.*;

@Service
public class TreasureEngine {




    // convert Treasure object to XML

    @Autowired
    private Treasure treasure;

    public String jaxbTreasureObjectToXML() {
        String xmlString = "";
        try {
            JAXBContext context = JAXBContext.newInstance(Treasure.class);
            Marshaller m = context.createMarshaller();

            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // To format XML

            StringWriter sw = new StringWriter();
            m.marshal(treasure, sw);
            xmlString = sw.toString();

        } catch (JAXBException e) {
            e.printStackTrace();
        }

        return xmlString;
    }

}
